#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>
int main()
{
pid_t ret=fork();
if(ret==0)
{
//子进程
int i=5;
while(i--)
{
printf("I am the child task,my pid is %d,my ppid is %d\n",getpid(),getppid());
sleep(1);
}
exit(20);
}
while(1)
{
int status=0;
pid_t w=waitpid(ret,&status,WNOHANG);
if(w>0)
{
printf("I am is parent task,I successfully return return the child,my pid is %d,my parent pid is %d, waitpid:%d,status node:%d,status info:%d\n",getpid(),getppid(),w,(status>>8)&0xFF,status&0x7F);
break;
}
if(w==0)
{
printf("I am doing other things\n");
}
sleep(1);
}





return 0;
}
